package com.cl.short_video_java.web.admin.shop;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cl.short_video_java.annotation.IsRole;
import com.cl.short_video_java.annotation.Log;
import com.cl.short_video_java.annotation.Login;
import com.cl.short_video_java.common.Const;
import com.cl.short_video_java.common.Result;
import com.cl.short_video_java.menum.BusinessType;
import com.cl.short_video_java.pojo.VideoShop;
import com.cl.short_video_java.service.VideoShopService;
import com.cl.short_video_java.vo.shop.ShopAdd;
import com.cl.short_video_java.vo.shop.ShopSearch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 付
 * @Date 2024-11-13 16:34
 * @Version 1.0
 * @description
 * @since 1.0
 */

@RestController
@RequestMapping("/shop")
public class ShopController {

	private VideoShopService videoShopService;

	@Autowired
	public ShopController(VideoShopService videoShopService) {
		this.videoShopService = videoShopService;
	}


	@PostMapping("/page")
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 6)
	public Result page(@RequestBody ShopSearch shop) {
		Page<VideoShop> page = videoShopService.page(shop);
		return Result.success(page);
	}

	@GetMapping("/limit")
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 6)
	public Result limit(@RequestParam("id") Integer id) {
		videoShopService.limit(id);
		return Result.success();
	}

	/**
	 * 批量删除商品
	 *
	 * @param ids
	 * @return
	 */
	@PostMapping("/del")
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 6)
	@Log(title = "商品",businessType = BusinessType.DELETE)
	public Result del(@RequestBody List<Integer> ids) {
		videoShopService.del(ids);
		return Result.success();
	}

	@PostMapping("/save")
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 6)
	@Log(title = "商品",businessType = BusinessType.INSERT)
	public Result save(@Validated @RequestBody ShopAdd shopAdd) {
		videoShopService.save(shopAdd);
		return Result.success();
	}


}
